<?php
namespace app\admin\controller;
use app\admin\BaseController;
use app\admin\model\Auth;
use think\facade\Request;
use think\facade\View;

class Admin extends BaseController{
    //用户的展示
    public function user()
    {
        $list=\app\admin\model\Admin::adminList();
        View::assign('list',$list);
        $id=Request::get('delId');
        if (isset($id)&&$id!=""){
            try{
                $list=\app\admin\model\Admin::userListDel($id);
                $msg='成功';
            }catch (\Exception $e){
                $list=false;
                $msg=$e->getMessage();
            }
            if ($list){
                $this->success($msg,url('Admin/userDel'));
            }else{
                $this->error($msg);
            }
        }
        return view();

    }
    //用户的添加
    public function userAdd()
    {
        //权限
        $auth=Auth::auth()->toArray();
        View::assign('auth',$auth);
        $file=\app\admin\logic\Admin::adminAddWhere();
        if (isset($file) && $file!=''){
            try{
                $list= \app\admin\model\Admin::adminAdd($file);
                $msg='成功';
            }catch (\Exception $e){
                $list=false;
                $msg=$e->getMessage();
            }
            if ($list){
                $this->success($msg,url('Admin/user'));
            }else{
                $this->error($msg);
            }
        }
        return view();
    }
    //用户的修改
    public function userEdit()
    {
        //权限
        $auth=Auth::auth()->toArray();
        View::assign('auth',$auth);
        $id=Request::get();
        if ($id!='' && isset($id)){
            $list=\app\admin\model\Admin::userEdit($id)->toArray();
            View::assign($list);
        }
        $where=\app\admin\logic\Admin::userEdit();
        if (isset($where) && $where!=""){
            try{
                $list=\app\admin\model\Admin::xiuUserEdit($where);
                $msg='成功';
            }catch (\Exception $e){
                $list=false;
                $msg=$e->getMessage();
            }
            if ($list){
                $this->success($msg,url('Admin/user'));
            }else{
                $this->error($msg);
            }
        }


        return view();
    }
    //用户的删除展示
    public function userDel()
    {
        $list=\app\admin\model\Admin::userList();
        View::assign('list',$list);
        $huiId=Request::get('huiId');
        if (isset($huiId)&&$huiId!=""){
            try{
                $list=\app\admin\model\Admin::huiUserDel($huiId);
                $msg='成功';
            }catch (\Exception $e){
                $list=false;
                $msg=$e->getMessage();
            }
            if ($list){
                $this->success($msg,url('Admin/user'));
            }else{
                $this->error($msg);
            }
        }
        $zhenId=Request::get('zhenId');
        if (isset($zhenId)&&$zhenId!=""){
            try{
                $list=\app\admin\model\Admin::zhenUserDel()($zhenId);
                $msg='删除成功';
            }catch (\Exception $e){
                $list=false;
                $msg=$e->getMessage();
            }
            if ($list){
                $this->success($msg,url('Admin/userDel'));
            }else{
                $this->error($msg);
            }
        }
        return view();
    }
}